﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DomainDriver.DomainModeling.Configuration;
using DomainDriver.DomainModeling.Constraints;
using DomainDriver.DomainModeling.DomainModels;
using DomainDriver.DomainModeling.Events;
using DomainDriver.DomainModeling.Repositories;
using AutomotivePricingModel.ValueObjects.MissingValueOptions;
using AutomotivePricingModel.ValueObjects.YearlyFinancialAssessments;

namespace AutomotivePricingModel.ValueObjects
{
    public class AssemblyRegistrar : IAssemblyRegistrar
    {
        public void RegisterDomainObjects(IDomainModel domainModel)
        {
            domainModel.RegisterDomainObjectRepository<MissingValueOptionEnum, int, MissingValueOption>();
        }

        public void ConfigureDataSource(IDomainModel sender, DataSourceConfigurationArgs args)
        { }

        public void CreateConstraints(IDomainModel domainModel, EventArgs args)
        {
            FixedValuesConstraint<MissingValueOptionEnum, MissingValueOption> missingValueOptionEnumConstraint = new FixedValuesConstraint<MissingValueOptionEnum, MissingValueOption>(domainModel, LoadMissingValueOptionValues);
            domainModel.AddModelConstraint(missingValueOptionEnumConstraint);
        }

        public static void LoadMissingValueOptionValues(IDomainModel domainModel)
        {
            Type enumType = typeof(MissingValueOptionEnum);
            IRepository<MissingValueOptionEnum, MissingValueOption> repository = domainModel.GetRepository<MissingValueOptionEnum, MissingValueOption>();

            foreach (MissingValueOptionEnum key in Enum.GetValues(enumType))
            {
                if (repository.Exists(key))
                { continue; }

                MissingValueOption domainObject = new MissingValueOption(key);
                repository.Add(domainObject);
            }
        }
    }
}